<?php
ifi!perms_check('pages', 'read')) {
	redirect('index.php?module=error&amp;error=auth_error');
	exit;
}

$db = new dbquery;

if(!$_GET['id'])
$_GET['id']=0;

SQLvalidate($_GET['id']);

//query start
$db->query("SELECT * FROM $conf[prefix]pages WHERE id=$_GET[id]") or $db->err(__FILE__, __LINE__);
$p = $db->fetch_object();

if($db->num_rows()==0 or $p->visible != 1) {
	redirect('index.php?module=error&amp;error=pages_error1');
	exit;
}
//

$t = 'text_'.$_SESSION['lang_short'];
$tl = 'title_'.$_SESSION['lang_short'];

if($p->$t == '') {
	$tl = "title_$conf[language]";
	$t = "text_$conf[language]";
}

$p->$tl=read_text_rest($p->$tl);

//site_title
$GLOBALS['lang']['global']['site_title']=$p->$tl.' - '.$GLOBALS['lang']['global']['site_title'];
$GLOBALS['lang']['global']['site_description']=read_text_rest(strip_exbcode(add_dots_($p->$t, 100))).' - '.$GLOBALS['lang']['global']['site_description'];

//adding {edit} & {delete} if user is admin
if(perms_check('pages', 'edit'))
$edit='<a href="index.php?module=admin&amp;action=pages&amp;cmd=edit&amp;id='.$p->id.'">'.$lang['admin_edit'].'</a>';
else
$edit='';
if(perms_check('pages', 'del'))
$delete='<a href="index.php?module=admin&amp;action=pages&amp;cmd=delete&amp;id='.$p->id.'">'.$lang['admin_delete'].'</a>';
else
$delete='';
//

//generating content of page
$content=string_template(read_file('pages.php'), array('author' => get_user_overlib_by_id($p->author), 'date' => date($conf['date_format'], strtotime($p->date)), 'edit' => $edit, 'delete' => $delete, 'id' => $p->id, 'title' => $p->$tl, 'text'=>read_text($p->$t)));

$description=read_text_rest($p->$tl);
$content=string_template(read_file('middle.php'), array('theme_path' => $GLOBALS['theme_path'], 'content' => $content, 'description' => $description));
//end

//generating menus (what, template)
$menu_left=menu('left', 'left');
$menu_right=menu('right', 'right');
$menu_top=menu('top', 'top');
//

//site_generation_time
$GLOBALS['time_end'] = microtime(1);
$site_generation_time=abs(round($GLOBALS['time_end']-$GLOBALS['time_start'], 3));
//

//creating template
$tpl=new tpl;
//header
$tpl->create('header.php', array('title' => $GLOBALS['lang']['global']['site_title'], 'description' => $GLOBALS['lang']['global']['site_description'], 'keywords' => $GLOBALS['lang']['global']['site_keywords'], 'theme_path'=>$GLOBALS['theme_path'], 'menu_top' => $menu_top));
//body
$tpl->create('body.php', array('theme_path' => $GLOBALS['theme_path'], 'menu_top' => $menu_top, 'menu_left' => $menu_left, 'menu_right' => $menu_right, 'content' => $content));
//footer
$tpl->create('footer.php', array('site_generation_time' => string_template($GLOBALS['lang']['global']['site_generation_time'], array('site_generation_time'=>$site_generation_time, 'queries'=>$db->query_count())), 'theme_path'=>$GLOBALS['theme_path'], 'copyright' => $GLOBALS['lang']['global']['site_copyright'], 'queries'=>$db->query_count()));
//parse
$tpl->parse();
?>
